package com.cqc.day03drawtext.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by ${cqc} on 2017/10/9.
 */

public class DrawTextView extends View {

    private Paint paint;
    private StaticLayout layout_1;

    public DrawTextView(Context context) {
        this(context, null);
    }

    public DrawTextView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DrawTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        paint = new Paint();
        paint.setTextSize(60);
        paint.setColor(Color.RED);


        TextPaint textPaint = new TextPaint();
        textPaint.setColor(Color.RED);
        textPaint.setTextSize(40);
        String text = "如果你需要进行多行文字的绘制，并且对文字的排列和样式没有太复杂的花式要求，那么使用 StaticLayout 就好.includeadd 是指是否在文字上下添加额外的空间，来避免某些过高的字符的绘制出现越界。";
        layout_1 = new StaticLayout(text,textPaint,600, Layout.Alignment.ALIGN_NORMAL,1,0,true);



    }



    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawText("Hello World", 200, 200, paint);

        canvas.save();
        canvas.translate(20,300);
        layout_1.draw(canvas);

    }
}
